﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IToolStrip</summary>
	public class IToolStrip : System.Windows.Forms.ToolStrip
	{
        /// <summary>Vytvorenie polozky menu</summary>
        /// <param name="pParent">rodicovska kolekcia</param>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt novej polozky</returns>
        public static IToolStripMenuItem CreateMenuItem(System.Windows.Forms.ToolStripItemCollection pParent, string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            IToolStripMenuItem MI = new IToolStripMenuItem(); // Vytvorim objekt
            MI.Text = pName; // Nastavim text
            if (pClickHandler != null) MI.Click += pClickHandler; // Nastavim handlery
            if (pOpeningHandler != null) MI.DropDownOpening += pOpeningHandler;
            pParent.Add(MI); // Zaradim do kolekcie
            return MI; // Vratim objekt
        }
        /// <summary>Vytvorenie dropdown tlacxdla</summary>
        /// <param name="pParent">rodicovska kolekcia</param>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt noveho tlacidla</returns>
        public static IToolStripDropDownButton CreateDropDownButton(System.Windows.Forms.ToolStripItemCollection pParent, string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            IToolStripDropDownButton MI = new IToolStripDropDownButton(); // Vytvorim objekt
            MI.Text = pName; // Nastavim text
            if (pClickHandler != null) MI.Click += pClickHandler; // Nastavim handlery
            if (pOpeningHandler != null) MI.DropDownOpening += pOpeningHandler;
            pParent.Add(MI); // Zaradim do kolekcie
            return MI; // Vratim objekt
        }
        /// <summary>Vytvorenie oddelovaca</summary>
        /// <param name="pParent">rodicovska kolekcia</param>
        /// <param name="pSkipIfExists">priznak preskocenia ak je poslednou polozkou oddelovac</param>
        public static void CreateSeparator(System.Windows.Forms.ToolStripItemCollection pParent, bool pSkipIfExists = false)
        {
            if (pSkipIfExists) { // Testujem
                if ((pParent.Count == 0) || (pParent[pParent.Count - 1].GetType().FullName.Contains("ToolStripSeparator"))) return;
            }

            pParent.Add(new System.Windows.Forms.ToolStripSeparator()); // Vytvorim a zaradim
        }
        /// <summary>Vytvorenie CMD polozky menu</summary>
        /// <param name="pParent">rodicovska kolekcia</param>
        /// <param name="pName">nazov</param>
        /// <param name="pCMD_ID">ID prikazu</param>
        /// <param name="pAPP_TARGET">aplikacia</param>
        /// <param name="pPANEL_TARGET">panel</param>
        /// <returns>objekt novej polozky</returns>
        public static IToolStripCMDMenuItem CreateCMDMenuItem(System.Windows.Forms.ToolStripItemCollection pParent, string pName, int pCMD_ID = ICmd.CMD_ID_NONE, int pAPP_TARGET = ICmd.CMD_APP_TARGET_NONE, int pPANEL_TARGET = ICmd.CMD_APP_TARGET_NONE)
        {
            IToolStripCMDMenuItem MI = new IToolStripCMDMenuItem(); // Vytvorim objekt
            MI.Text = pName; // Nastavim text
            MI.CMD_ID = pCMD_ID; MI.APP_TARGET = pAPP_TARGET; MI.PANEL_TARGET = pPANEL_TARGET; // Ulozim
            MI.Click += IApp.CMD.Event_OnCmdMenuItemClick; // Nastavim event
            pParent.Add(MI); // Zaradim
            return MI; // Vratim objekt
        }

        /// <summary>Vytvorenie polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripMenuItem CreateMenuItem(string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            return CreateMenuItem(Items, pName, pClickHandler, pOpeningHandler); // Volam vytvorenie
        }
        /// <summary>Vytvorenie dropdown tlacxdla</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt noveho tlacidla</returns>
        public IToolStripDropDownButton CreateDropDownButton(string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            return CreateDropDownButton(Items, pName, pClickHandler, pOpeningHandler); // Volam vytvorenie
        }
        /// <summary>Vytvorenie oddelovaca</summary>
        public void CreateSeparator(bool pRightAlign = false)
        {
            CreateSeparator(Items); // Volam vytvorenie
            if (pRightAlign) Items[Items.Count - 1].Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
        }
        /// <summary>Vytvorenie CMD polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pCMD_ID">ID prikazu</param>
        /// <param name="pAPP_TARGET">aplikacia</param>
        /// <param name="pPANEL_TARGET">panel</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripCMDMenuItem CreateCMDMenuItem(string pName, int pCMD_ID = ICmd.CMD_ID_NONE, int pAPP_TARGET = ICmd.CMD_APP_TARGET_NONE, int pPANEL_TARGET = ICmd.CMD_APP_TARGET_NONE)
        {
            return IToolStrip.CreateCMDMenuItem(Items, pName, pCMD_ID, pAPP_TARGET, pPANEL_TARGET); // Volam vytvorenie
        }
    }

    /// <summary>Trieda IToolStripMenuItem</summary>
    public class IToolStripMenuItem : System.Windows.Forms.ToolStripMenuItem
    {
        public string UserParameter; // Uzivatelsky parameter

        /// <summary>Vytvorenie polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripMenuItem CreateMenuItem(string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            return IToolStrip.CreateMenuItem(DropDownItems, pName, pClickHandler, pOpeningHandler); // Volam vytvorenie
        }
        /// <summary>Vytvorenie oddelovaca</summary>
        public void CreateSeparator()
        {
            IToolStrip.CreateSeparator(DropDownItems); // Volam vytvorenie
        }
        /// <summary>Vytvorenie CMD polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pCMD_ID">ID prikazu</param>
        /// <param name="pAPP_TARGET">aplikacia</param>
        /// <param name="pPANEL_TARGET">panel</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripCMDMenuItem CreateCMDMenuItem(string pName, int pCMD_ID = ICmd.CMD_ID_NONE, int pAPP_TARGET = ICmd.CMD_APP_TARGET_NONE, int pPANEL_TARGET = ICmd.CMD_APP_TARGET_NONE)
        {
            return IToolStrip.CreateCMDMenuItem(DropDownItems, pName, pCMD_ID, pAPP_TARGET, pPANEL_TARGET); // Volam vytvorenie
        }
    }

    /// <summary>Trieda IToolStripCMDMenuItem</summary>
    public class IToolStripCMDMenuItem : IToolStripMenuItem
    {
        public int CMD_ID;
        public int APP_TARGET;
        public int PANEL_TARGET;
    }

    /// <summary>Trieda IToolStripDropDownButton</summary>
    public class IToolStripDropDownButton : System.Windows.Forms.ToolStripDropDownButton
    {
        /// <summary>Vytvorenie polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pClickHandler">Click handler</param>
        /// <param name="pOpeningHandler">DropDownOpening handler</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripMenuItem CreateMenuItem(string pName, EventHandler pClickHandler = null, EventHandler pOpeningHandler = null)
        {
            return IToolStrip.CreateMenuItem(DropDownItems, pName, pClickHandler, pOpeningHandler); // Volam vytvorenie
        }
        /// <summary>Vytvorenie oddelovaca</summary>
        public void CreateSeparator()
        {
            IToolStrip.CreateSeparator(DropDownItems); // Volam vytvorenie
        }
        /// <summary>Vytvorenie CMD polozky menu</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pCMD_ID">ID prikazu</param>
        /// <param name="pAPP_TARGET">aplikacia</param>
        /// <param name="pPANEL_TARGET">panel</param>
        /// <returns>objekt novej polozky</returns>
        public IToolStripCMDMenuItem CreateCMDMenuItem(string pName, int pCMD_ID = ICmd.CMD_ID_NONE, int pAPP_TARGET = ICmd.CMD_APP_TARGET_NONE, int pPANEL_TARGET = ICmd.CMD_APP_TARGET_NONE)
        {
            return IToolStrip.CreateCMDMenuItem(DropDownItems, pName, pCMD_ID, pAPP_TARGET, pPANEL_TARGET); // Volam vytvorenie
        }
    }
}
